home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / performCutKeyArgList.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  13.6 KB  |  479 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  August 14, 1996
  22. //
  23. //  Description:
  24. //      This is a helper script to perfrom the cutKey command
  25. //    using the various options that have been set
  26. //
  27. //  Input Arguments:
  28. //        int action        0 - just execute the command
  29. //                        1 - show the option box dialog
  30. //                        2 - return the drag command
  31. //
  32. //  Return Value:
  33. //      None.
  34. //
  35.  
  36. proc setOptionVars (int $forceFactorySettings)
  37. {
  38.     keySetOptionBoxCommon( { "cutKey", 
  39.                              "unknown",
  40.                              "setOptionVars", 
  41.                              $forceFactorySettings } );
  42.  
  43.  
  44.     // -options
  45.     //
  46.     if ($forceFactorySettings || !`optionVar -exists cutKeyOption`) {
  47.         optionVar -stringValue cutKeyOption "keys";
  48.     }
  49.  
  50.     // help images
  51.     //
  52.     if ($forceFactorySettings || !`optionVar -exists cutKeyHelpPictures`) {
  53.         optionVar -intValue cutKeyHelpPictures 0;
  54.     }
  55. }
  56.  
  57. global proc cutKeySetup (string $parent, string $selectionConnection, int $forceFactorySettings)
  58. {
  59.     // Retrieve the option settings
  60.     //
  61.     setOptionVars( $forceFactorySettings );
  62.  
  63.     setParent $parent;
  64.  
  65.     keySetOptionBoxCommon( { "cutKey", $selectionConnection, "setup" } );
  66.  
  67.     // -option
  68.     //
  69.     string $option = `optionVar -query cutKeyOption`;
  70.     int $attach = 1;
  71.     int $connect = 0;
  72.  
  73.     if (substring ($option, 1, 4) == "keys") {
  74.         radioButtonGrp -edit -select 1    method;
  75.     }
  76.     else {
  77.         radioButtonGrp
  78.             -edit
  79.             -select 2
  80.             method;
  81.         if ($option == "curveCollapse") {
  82.             $attach = 2;
  83.         }
  84.         else if ($option == "curveConnect") {
  85.             $attach = 2;
  86.             $connect = 1;
  87.         }
  88.     }
  89.     radioButtonGrp -edit -select $attach adjustment;
  90.     checkBoxGrp -e -value1 $connect connect;
  91.  
  92.     // help images
  93.     //
  94.     int $pictures = `optionVar -q cutKeyHelpPictures`;
  95.     checkBoxGrp -e -value1 $pictures helpPictures;
  96.  
  97.     // Now get all the dependent widgets in the right 
  98.     // enabled/disabled/collapsed/expanded state
  99.     //
  100.     cutKeyWidgetsEnable ($selectionConnection);
  101. }
  102.  
  103. global proc cutKeyCallback( string $parent, int $doIt, 
  104.                             string $selectionConnection, 
  105.                             int $fromGraphEditor,
  106.                             int $performAction )
  107. {
  108.     setParent $parent;
  109.  
  110.     keySetOptionBoxCommon( { "cutKey", $selectionConnection, "callback" } );
  111.  
  112.     // -option
  113.     //
  114.     string $option;
  115.     if (`radioButtonGrp -query -select method` == 1) {
  116.         $option = "keys";
  117.     }
  118.     else {
  119.         $option = "curve";
  120.     }
  121.  
  122.     if (`radioButtonGrp -query -select adjustment` == 2) {
  123.         if( `checkBoxGrp -query -value1 connect` ) {
  124.             $option = $option + "Connect";
  125.         } else {
  126.             $option = $option + "Collapse";
  127.         }
  128.     }
  129.  
  130.     optionVar -stringValue cutKeyOption $option;
  131.  
  132.     // help
  133.     //
  134.     int $pictures = `checkBoxGrp -query -value1 helpPictures`;
  135.     optionVar -intValue cutKeyHelpPictures $pictures;
  136.  
  137.     if( $doIt ) {
  138.         performCutKeyArgList 1 { (string) $performAction,
  139.                                  $selectionConnection, 
  140.                                  (string) $fromGraphEditor };
  141.         string $tmpCmd = "performCutKeyArgList 1 {\"";
  142.         $tmpCmd += $performAction + "\", \"";
  143.         $tmpCmd += $selectionConnection + "\", \"";
  144.         $tmpCmd += $fromGraphEditor + "\"}";
  145.         addToRecentCommandQueue $tmpCmd "Cut Key";
  146.     }
  147. }
  148.  
  149. global proc cutKeyHelpPictures ()
  150. {
  151.     int $doPictures = (`checkBoxGrp -q -value1 helpPictures` &&
  152.                        `checkBoxGrp -q -enable helpPictures`);
  153.  
  154.     if( $doPictures == 0 ) {
  155.         frameLayout -e -collapse yes methodPictureFrame;
  156.         frameLayout -e -collapse yes adjustmentPictureFrame;
  157.         return;
  158.     }
  159.  
  160.     int $method = `radioButtonGrp -q -select method`;
  161.     int $adjustment = `radioButtonGrp -q -select adjustment`;
  162.  
  163.     string $adjustmentPicture = "CCP";
  164.     string $methodPicture;
  165.  
  166.     if( $method == 1 ) {
  167.         $adjustmentPicture = $adjustmentPicture + "cutKeys";
  168.         $methodPicture = "CCPkeyframesOnly.xpm";
  169.     } else {
  170.         $adjustmentPicture = $adjustmentPicture + "cutCurve";
  171.         $methodPicture = "CCPcurveExact.xpm";
  172.     }
  173.  
  174.     if( $adjustment == 2 ) {
  175.         if( `checkBoxGrp -q -value1 connect` ) {
  176.             $adjustmentPicture = $adjustmentPicture + "Connect.xpm";
  177.         } else {
  178.             $adjustmentPicture = $adjustmentPicture + "Collapse.xpm";
  179.         }
  180.     } else {
  181.         $adjustmentPicture = $adjustmentPicture + ".xpm";
  182.     } 
  183.  
  184.     picture -e -image $methodPicture methodPicture;
  185.     picture -e -image $adjustmentPicture adjustmentPicture;
  186.  
  187.     frameLayout -e -collapse no methodPictureFrame;
  188.     frameLayout -e -collapse no adjustmentPictureFrame;
  189. }
  190.  
  191.  
  192. global proc cutKeyDoSelectionChanged (string $selectionConnection)
  193. //
  194. // Description:
  195. //    Since timeRange is irrelevant when there are 
  196. //    picked keyframes, collapse the timeRange
  197. //    when there are.  (This is hooked in to a SelectionChanged
  198. //    trigger.)
  199. //    
  200. {
  201.     keySetOptionBoxCommon( { "cutKey", $selectionConnection, "selectionChanged" } );
  202.  
  203.     if( `keyframe -q -sl -kc` > 0) {
  204.         radioButtonGrp -e -enable2 false -select 1 method;
  205.         radioButtonGrp -e -enable2 false -select 1 adjustment;
  206.     } else if( `radioButtonGrp -q -enable method` ) {
  207.         radioButtonGrp -e -enable2 true method;
  208.     }
  209. }
  210.  
  211.  
  212. global proc cutKeyWidgetsEnable (string $selectionConnection)
  213. //
  214. // Description:
  215. //    These are the widgets that get enabled and
  216. //    disabled based on the certain states.  Put them
  217. //    here so they're all in one place.
  218. //    
  219. {
  220.     keySetOptionBoxCommon( { "cutKey", $selectionConnection, "enable" } );
  221.  
  222.     // Options frame
  223.     //
  224.     int $enableIt = ( `radioButtonGrp -q -select timeRange` != 1 );
  225.     frameLayout -e -enable $enableIt optionsFrame;
  226.  
  227.     // Collapse adjustment
  228.     //
  229.     $enableIt = (( `radioButtonGrp -q -select method` == 2 ) &&
  230.                  ( `radioButtonGrp -q -enable2 method` ));
  231.     radioButtonGrp -e -enable2 $enableIt adjustment;
  232.     if( !$enableIt && `radioButtonGrp -q -enable method` ) {
  233.         radioButtonGrp -e -select 1 adjustment;
  234.     }
  235.  
  236.     // Connect Check box
  237.     //
  238.     $enableIt = (( `radioButtonGrp -q -select adjustment` == 2 ) &&
  239.                  ( `radioButtonGrp -q -enable2 adjustment` ));
  240.     checkBoxGrp -e -enable $enableIt connect;
  241.  
  242.     cutKeyHelpPictures;
  243. }
  244.  
  245. proc string cutKeyWidgets( string $tabLayout, string $selectionConnection, int $fromGraphEditor )
  246. {
  247.     global int $gOptionBoxTextColumnWidthIndex;
  248.  
  249.     setParent $tabLayout;
  250.  
  251.     string $tabForm = `columnLayout -adjustableColumn true`;
  252.  
  253.     keySetOptionBoxCommon( { "cutKey", $selectionConnection, "widgets", $fromGraphEditor } );
  254.  
  255.     frameLayout -bv no -lv no -collapsable no optionsFrame;
  256.         columnLayout -adjustableColumn true;
  257.  
  258.             checkBoxGrp -label "Help Images" -ncb 1 -value1 off -l1 "" 
  259.                 -cc1 "cutKeyHelpPictures;" 
  260.                 helpPictures;
  261.  
  262.             radioButtonGrp -numberOfRadioButtons 2 -label "Method" 
  263.                 -label1 "Keys" 
  264.                 -cc1 ("cutKeyWidgetsEnable " + $selectionConnection)
  265.                 -label2 "Segments" 
  266.                 -cc2 ("cutKeyWidgetsEnable " + $selectionConnection) method;
  267.  
  268.             frameLayout -bv no -lv no -collapsable yes -collapse yes 
  269.                 methodPictureFrame;
  270.  
  271.                 columnLayout -columnAttach "left" $gOptionBoxTextColumnWidthIndex;
  272.                     picture methodPicture;
  273.                     setParent ..;
  274.                 setParent ..;
  275.                     
  276.             radioButtonGrp -numberOfRadioButtons 2 -label "Adjustment" 
  277.                 -label1 "None" 
  278.                 -cc1 ("cutKeyWidgetsEnable " + $selectionConnection)
  279.                 -label2 "Collapse" 
  280.                 -cc2 ("cutKeyWidgetsEnable " + $selectionConnection)
  281.                 adjustment;
  282.  
  283.             checkBoxGrp -label "Connect" -ncb 1 -l1 "" -value1 off 
  284.                 -cc1 "cutKeyHelpPictures;" connect;
  285.  
  286.             frameLayout -bv no -lv no -collapsable yes -collapse yes 
  287.                 adjustmentPictureFrame;
  288.  
  289.                 columnLayout -columnAttach "left" 
  290.                     $gOptionBoxTextColumnWidthIndex;
  291.  
  292.                     picture adjustmentPicture;
  293.  
  294.                     setParent ..;
  295.                 setParent ..;
  296.  
  297.             setParent ..;    
  298.  
  299.         setParent ..;    
  300.  
  301.     return $tabForm;
  302. }
  303.  
  304. proc cutKeyOptions ( string $selectionConnection, int $performAction, int $fromGraphEditor )
  305. {
  306.     // Customisation options
  307.     //
  308.     // Name of the command for this option box (think of it as the base class)
  309.     string $commandName = "cutKey";
  310.     // Title for the option box window
  311.     string $optionBoxTitle = "Cut Keys Options";
  312.     // Title for the apply button
  313.     string $applyTitle = "Cut keys";
  314.  
  315.     // Build the option box "methods"
  316.     //
  317.     string $callback = ($commandName + "Callback");
  318.     string $setup = ($commandName + "Setup");
  319.  
  320.     // Build the window, with a tab layout
  321.     //
  322.     string $widgetList[] = `getStandardWindow $optionBoxTitle 0 "noOptions"`;
  323.     setUITemplate -pushTemplate DefaultTemplate;
  324.  
  325.     // Make the form invisible while we create the widgets in the window
  326.     //
  327.     formLayout -e -vis false $widgetList[1];
  328.  
  329.     // Attach the widgets.  No tab layout needed.
  330.     //
  331.     cutKeyWidgets $widgetList[2] $selectionConnection $fromGraphEditor;
  332.  
  333.     // Attach the standard buttons
  334.     //
  335.     string $buttonList[] = `addStandardButtons $commandName $applyTitle 
  336.         $widgetList[1] $widgetList[2] "noOptions"`;
  337.  
  338.     // attach commands to the standard buttons
  339.     //
  340.     // Save
  341.     //
  342.     button -e -c ($callback + " " + $widgetList[0] + " false \"\" " + 
  343.                   $fromGraphEditor + " " + $performAction +
  344.                   "; hideOptionBox()") $buttonList[3];
  345.     
  346.     // Close
  347.     //
  348.     button -edit -command hideOptionBox $buttonList[2];
  349.  
  350.     // Reset
  351.     //
  352.     button -edit -command ($setup + " " + $widgetList[0] + " " + $selectionConnection + " true") 
  353.         $buttonList[1];
  354.  
  355.     // Do It
  356.     //
  357.     button -edit -command ($callback + " " + $widgetList[0] + " true \"" + 
  358.                            $selectionConnection + "\"" + $fromGraphEditor + 
  359.                            " " + $performAction) $buttonList[0];
  360.  
  361.     // Make the form layout visible so we can see what we built, and
  362.     // reset the template
  363.     //
  364.     formLayout -e -vis true $widgetList[1];
  365.     setUITemplate -popTemplate;
  366.  
  367.     //    Customize the 'Help' menu item text.
  368.     //    This is called from 3 different places so look at the selection
  369.     //    connection to try to figure out which one.
  370.     //
  371.     if (match ("graphEditor", $selectionConnection) != "") {
  372.         setOptionBoxHelpTag( "GraphCut" );
  373.     } else if (match ("dopeSheet", $selectionConnection) != "") {
  374.         setOptionBoxHelpTag( "DopeCut" );
  375.     } else {
  376.         setOptionBoxHelpTag( "KeysCutKeys" );
  377.     }
  378.  
  379.     // Call the setup "method" to fill in the current settings
  380.     //
  381.     eval (($setup + " " + $widgetList[0] + " " + $selectionConnection + " false"));    
  382.     showOptionBox();
  383.     showWindow $widgetList[0];
  384.  
  385.     if( $fromGraphEditor ) {
  386.         cutKeyDoSelectionChanged($selectionConnection);    
  387.         scriptJob -protected -event "SelectionChanged" 
  388.             ("cutKeyDoSelectionChanged " + $selectionConnection + "; cutKeyWidgetsEnable " + $selectionConnection + ";")
  389.             -parent $widgetList[2];
  390.     }
  391. }
  392.  
  393. proc string assembleCmd( string $selectionConnection, int $fromGraphEditor,
  394.                          string $options ) 
  395. {
  396.     // doCutKeyArgList takes a string array.
  397.     //
  398.     string $cmd = "doCutKeyArgList 3 { " +
  399.                     "\"" + `optionVar -q cutKeyWhichRange` + "\"" + 
  400.                     ",\"" + `optionVar -q cutKeyRange` + "\"" + 
  401.                     ",\"" + `optionVar -q cutKeyOption` + "\"" + 
  402.                     ",\"" + `optionVar -q cutKeyHierarchy` + "\"" + 
  403.                     ",\"" + `optionVar -q cutKeyControlPoints` + "\"" + 
  404.                     ",\"" + `optionVar -q cutKeyShapes` + "\"" + 
  405.                     ",\"" + `optionVar -q cutKeyUseChannelBox` + "\"" + 
  406.                     ",\"" + $selectionConnection + "\"" + 
  407.                     ",\"" + $options + "\"" +
  408.                     ",\"" + $fromGraphEditor + "\"" +
  409.                     ",\"" + `optionVar -q cutKeyDriven`+ "\"" +
  410.                 " };";
  411.  
  412.     return $cmd;
  413. }
  414.  
  415. global proc string performCutKeyArgList (string $version, string $args[])
  416. //
  417. //  Input Arguments:
  418. //    $version: The version of this option box.  Used to know how to 
  419. //    interpret the $args array.
  420. //        "1" : $action, $selectionConnection, $fromGraphEditor
  421. //
  422. //    $args
  423. //    Version 1
  424. //    [0]        $action                    0 - do the command
  425. //                                    1 - show the option box
  426. //                                    2 - return the drag command
  427. //                                    3 - do the command (bufferCurve version)
  428. //                                    4 - show the option box (bufferCurve version)
  429. //                                    5 - return the drag command (bufferCurve version)
  430. //    [1]        $selectionConnection    name of selection connection to use
  431. //                                    unless $options has "bufferCurve" in which
  432. //                                    case this is the name of the editor
  433. //    [2]        $fromGraphEditor        true if being called from the graph editor
  434. //
  435. //  Return Value:
  436. //      The actual command to execute.
  437. //
  438. {
  439.     int        $versionNum                = $version;
  440.  
  441.     int        $action                    = $args[0];
  442.     string    $selectionConnection    = $args[1];
  443.     int        $fromGraphEditor        = $args[2];
  444.  
  445.     string $cmd = "";
  446.  
  447.     switch( $action ) {
  448.     case 0:
  449.         setOptionVars( false );
  450.         $cmd = assembleCmd( $selectionConnection, $fromGraphEditor, 
  451.                             "noOptions" );
  452.         eval( $cmd );
  453.         break;
  454.     case 1:
  455.         cutKeyOptions( $selectionConnection, 0, $fromGraphEditor );
  456.         break;
  457.     case 2:
  458.         setOptionVars( false );
  459.         $cmd = assembleCmd( $selectionConnection, $fromGraphEditor, 
  460.                             "noOptions" );
  461.         break;
  462.     case 3:
  463.         setOptionVars( false );
  464.         $cmd = assembleCmd( $selectionConnection, $fromGraphEditor, 
  465.                             "bufferCurve" );
  466.         eval( $cmd );
  467.         break;
  468.     case 4:
  469.         cutKeyOptions( $selectionConnection, 3, $fromGraphEditor );
  470.         break;
  471.     case 5:
  472.         setOptionVars( false );
  473.         $cmd = assembleCmd( $selectionConnection, $fromGraphEditor, 
  474.                             "bufferCurve" );
  475.         break;
  476.     }
  477.     return ($cmd);
  478. }
  479.